<?php


namespace Part19_CombinationMode\Code1;

require_once '../../autoload.php';

// 树根节点root，有2树叶节点leafA leafB
$root = new Composite('root');
$root->add(new Leaf('Leaf A'));
$root->add(new Leaf('Leaf B'));

// 分枝CompositeX,也有2树叶节点LeafXA和LeafXB
$comp = new Composite('Composite X');
$comp->add(new Leaf('Leaf XA'));
$comp->add(new Leaf('Leaf XB'));
$root->add($comp);

// 在分枝CompositeX再长出分枝CompositeXY,也有2树叶节点LeafXYA和LeafXYB
$comp2 = new Composite('Composite XY');
$comp2->add(new Leaf('Leaf XYA'));
$comp2->add(new Leaf('Leaf XYB'));
$comp->add($comp2);

// 根部长出两叶子LeafC和LeafD,D被吹走了
$root->add(new Leaf('Leaf C'));
$leaf = new Leaf('leaf D');
$root->add($leaf);
$root->remove($leaf);

// 显示大树的样子
$root->display(1);